package com.example.person_web.core.component;

import com.example.person_web.core.entity.UserContext;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
@Component
public class JwtInterceptor implements HandlerInterceptor {
    // 关键：请求处理完成后清理ThreadLocal
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
                                Object handler, Exception ex) {
        // 无论请求处理成功与否，都必须清理
        UserContext.clear();
    }
}
